package com.ruoyi.web.controller.system;

import java.util.Comparator;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LsNavigation;
import com.ruoyi.system.service.ILsNavigationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 导航栏Controller
 *
 * @author zhouyipeng
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/system/navigation")
public class LsNavigationController extends BaseController
{
    @Autowired
    private ILsNavigationService lsNavigationService;

    /**
     * 查询导航栏列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LsNavigation lsNavigation)
    {
        List<LsNavigation> list = lsNavigationService.selectLsNavigationList(lsNavigation);
        list.sort(Comparator.comparing(LsNavigation::getMenuSort));
        return getDataTable(list);
    }

    /**
     * 导出导航栏列表
     */
    @Log(title = "导航栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LsNavigation lsNavigation)
    {
        List<LsNavigation> list = lsNavigationService.selectLsNavigationList(lsNavigation);
        ExcelUtil<LsNavigation> util = new ExcelUtil<LsNavigation>(LsNavigation.class);
        util.exportExcel(response, list, "导航栏数据");
    }

    /**
     * 获取导航栏详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(lsNavigationService.selectLsNavigationById(id));
    }

    /**
     * 新增导航栏
     */
    @PreAuthorize("@ss.hasPermi('system:navigation:add')")
    @Log(title = "导航栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LsNavigation lsNavigation)
    {
        return toAjax(lsNavigationService.insertLsNavigation(lsNavigation));
    }

    /**
     * 修改导航栏
     */
    @PreAuthorize("@ss.hasPermi('system:navigation:edit')")
    @Log(title = "导航栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LsNavigation lsNavigation)
    {
        return toAjax(lsNavigationService.updateLsNavigation(lsNavigation));
    }

    /**
     * 删除导航栏
     */
    @PreAuthorize("@ss.hasPermi('system:navigation:remove')")
    @Log(title = "导航栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(lsNavigationService.deleteLsNavigationByIds(ids));
    }
}
